<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      class Element {
        constructor(getData, render) {
          if (getData) {
            this.getData = getData;
          }
          if (render) {
            this.render = render;
          }
        }
        init() {
          this.getData();
          this.render();
        }
        getData() {
          throw Error(
            "抽象方法必须先实现，再调用。请传入 getData 的具体实现方法"
          );
        }

        render() {
          throw Error(
            "抽象方法必须先实现，再调用。请传入 render 的具体实现方法"
          );
        }
      }

      const e1 = new Element(
        () => {
          console.log("getData() 进行中");
        },
        () => {
          console.log("render() 进行中");
        }
      );

      console.log(e1);

      e1.init();
    </script>
  </body>
</html>
